import { defineStore } from 'pinia'
import type { AnyObject, ILocation, ISubscribeInfo } from '@/common/types'
import type { ShallowRef } from 'vue'
import {getRealNameAuth} from "@/common/api";

const useUserStore = defineStore('userStore', () => {
  const openid = ref('')
  const userData:ShallowRef<AnyObject> = shallowRef({})
  const userInfo:ShallowRef<AnyObject> = shallowRef({})
  const realNameInfo:ShallowRef<AnyObject> = shallowRef({})
  const location:ShallowRef<ILocation> = shallowRef({
    lat: '',
    lng: ''
  })
  const token = computed(() => userData.value.token)
  const uid = computed(() => userData.value.uid)
  const canPay = ref(true)
  const subscribeInfo = shallowRef<ISubscribeInfo>({
    userRemark: '',
    username: '',
    userGender: 0,
    userTel: '',
    userWx: '',
    userAddress: '',
    userAddressSecond: '',
    serviceTimeStr: ''
  })

  const clearUser = ():void => {
    userData.value = {}
    userInfo.value = {}
    realNameInfo.value = {}
  }

  function setSubscribeInfo(value: ISubscribeInfo) {
    subscribeInfo.value = value
  }

  return {
    userData,
    userInfo,
    realNameInfo,
    token,
    uid,
    openid,
    location,
    canPay,
    subscribeInfo,
    clearUser,
    setSubscribeInfo
  }
})

export default useUserStore
